<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" type="text/css" href="<%=path %>/static/css/css.css?1" />
<link rel="stylesheet" type="text/css" href="<%=path %>/static/jquery-ui/jquery-ui.min.css" />
<script type="text/javascript" src="<%=path %>/static/js/json2.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/jquery.js"></script>
<script type="text/javascript" src="<%=path %>/static/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=path %>/static/layer/layer.js"></script>
<script type="text/javascript" src="<%=path %>/static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="<%=path %>/static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/gridview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/formview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/tool.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/validate.js"></script>

<SCRIPT type="text/javascript">
    <!--
    var formSetting = {
    		po:'QhAdverAccount',
    		title:"",
    		formid:"formedit",
    		hiddens:["id","uid","type","expend","createUser","createDateTime","modifyUser","modifyDateTime","state"],
    	fields:[
    	     [
             	{tdwidth:100,title:"广告主",type:"text",name:"uName",width:150,datatype:"Require",msg:"请选择广告主！"}
             ],
    	     [
				{title:"金额",type:"text",name:"deposit",width:150,datatype:"Money",msg:"请输入格式正确的金额！"}
    		 ],
             [
                {title:"备注",type:"text",name:"note",width:550}
             ]
             ],
		toolbar:{align:'right',buttons:[
		                 			  {
		                 			    	 id:'save',
		                 			    	 title:'保存',
		                 			    	 handlers:{
		                 			    		 click: function(){
		                 			    			 if(!Validator.Validate(document.getElementById('formedit'),0)){
		                 			    			    return;
		                 			    			 }
		                 			    			 $("input[name=type]").val("充值");
		                 			    			 $("input[name=expend]").val(0);

		                 			    			 form.save(function(ret) {
		                 			    				if (ret == -1) {
		                 			    					layer.alert("数据保存失败，请重试！");
		                 			    				} else {
		                 			    				    if('${sessionScope.userInfo.type}'=="A"){
		                 			    				        $.getJSON(g_path+"/public/common/rechargeStateEdit.htmls",{id:ret.id,state:1},function(data){
		                 			    				           $.getJSON(g_path+"/public/common/editUserFund.htmls",{id:$("input[name=uid]").val(),money:$("input[name=deposit]").val()},function(data){
                                                                      layer.msg("数据已保存！");
                                                                   });
                                                                });
		                 			    				    }
		                 			    				    else{
		                 			    				        layer.msg("数据已保存！");
		                 			    				    }
		                 			    				}
		                 			    			});
		                 			    		 }
		                 			    	 }
		                 			     }
		                 			 ]}
    }

	var form;
    $(document).ready(function(){
    	form = new FormView("formview",formSetting);
    	form.init();

    	$.getJSON(g_path+"/public/common/getAdver.htmls",{},function(data){
        	var html="";
        	$.each(data,function(i,item){
        	   html+="<option value='"+item.id+"'>"+item.name+"</option>";
        	});
        	$("select[name=uid]").html(html);
        });

    	var id='${param.id}';
    	if(id!=null&&id!=""){
    	   form.loadData(id, "QhAdverAccount");
    	}

    	if('${sessionScope.userInfo.type}'=="B"){
    	   $("tr[rowindex=1]").hide();
    	   $("input[name=uid]").val('${sessionScope.userInfo.id}');
    	   $("input[name=uName]").val('${sessionScope.userInfo.id}');
    	}

		ajustHeight();
    });

    //-->
</SCRIPT>
</head>

<body>
<ul class=tab_nav>
  <li>
    <a href="/qh/public/common/r2.htmls?page=account/recharge_list">列表</a>
  </li>
  <li>
    <a href="" class="current">新增</a>
  </li>
</ul>
<div class="contrainer">
<div id="formview0" class="rbox1"></div>
<div id="formview" class="rbox1" style="margin-top:10px;"></div>
<div id="list" class="rbox2"></div>
<div id="alertBox_user" style="display:none">

      <table class="ctable">
         <tr>
            <td><input type="text" id="txtName" placeholder="请输入姓名" /></td>
            <td>
               <input type="button" id="btnSearch" class="btn2" value="查询" />
               <input type="button" id="btnSel" class="btn2" value="全选" onclick="checkAlls('selUser_ul',this)" />
            </td>
         </tr>
      </table>

   <div id="alertBox_user1"></div>
</div>
</div>
<script type="text/javascript" src="<%=path %>/static/js/underscore.js"></script>
<script type='text/javascript' src='<%=path %>/static/My97DatePicker/WdatePicker.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/interface/BaseDwr.js'></script>
<script>
   $(function(){
      loadData();
      $("#btnSearch").click(function(){
         loadData();
      });
   });
   function loadData(){
      $.getJSON(g_path+"/public/common/getAdver.htmls",{name:$("#txtName").val()},function(data){

         var html="<ul class='selUser_ul' id='selUser_ul'>";

         $.each(data,function(i,item){
            html+="<li><input type='radio' id='rdoUser"+i+"' name='rdoUser' value='"+item.id+"' /><label for='rdoUser"+i+"'>"+item.name+"</label></li>";
         });
         html+="</ul>";

         $("#alertBox_user1").html(html);
      });
   }

   var $$ = function(func){
           if (document.addEventListener) {
               window.addEventListener("load", func, false);
           }
           else if (document.attachEvent) {
               window.attachEvent("onload", func);
           }
       }
       $$(function(){
           $("input[name=uName]").click(function(){
               layer.open({
                 	title : "选择广告主",
                 	type : 1,
                 	skin : 'layui-layer-rim', // 加上边框
                 	area : [ '450px', '380px' ], // 宽高
                 	content : $("#alertBox_user"),
                 	btn : [ "确认","关闭" ],
                 	yes : function(index, layero) {
                 	    var str=$("input[name='rdoUser']:checked").next().text();
                 	    var strid=$("input[name='rdoUser']:checked").val();

                 	    $("input[name=uName]").val(str);
                 	    $("input[name=uid]").val(strid);
                        layer.close(index);
                 	},
                 	end : function(ret) {
                   }
               });
           });

       });
</script>
</body>
</html>